import sys

sys.setrecursionlimit(100000)
n = int(input())
edges = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)

max_d = 0


def dfs(curr, fa):
    """
    :param curr:
    :param fa:
    :return: 最长两个链
    """
    global max_d
    temp = []
    for next in edges[curr]:
        if next == fa:
            continue
        child_dis = dfs(next, curr)
        temp.append(max(child_dis) + 1)

    temp.sort(reverse=True)
    d1 = temp[0] if len(temp) > 0 else 0
    d2 = temp[1] if len(temp) > 1 else 0
    max_d = max(max_d, d1 + d2)
    return [d1, d2]


r = dfs(1, 0)
print(max_d)
